package com.sfy.mallchat.common.user.dao;

import com.sfy.mallchat.common.common.enums.YesOrNoEnum;
import com.sfy.mallchat.common.user.domain.entity.User;
import com.sfy.mallchat.common.user.domain.enums.BlackEnum;
import com.sfy.mallchat.common.user.mapper.UserMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2024-10-09
 */
@Service
public class UserDao extends ServiceImpl<UserMapper, User> {

    public User getByName(String name) {
        return lambdaQuery().eq(User::getName, name).one();
    }

    public void modifyName(Long uid, String name) {
        lambdaUpdate()
                .eq(User::getId, uid)
                .set(User::getName, name)
                .update();
    }

    public void wearingBadge(Long uid, Long badgeId) {
        User update = new User();
        update.setId(uid);
        update.setItemId(badgeId);
        updateById(update);
    }

    public void insert(User insert) {
        User user = new User();
        BeanUtils.copyProperties(insert, user);
        save(user);
    }

    public void isvalid(Long id) {
        lambdaUpdate()
                .eq(User::getId, id)
                .set(User::getStatus, YesOrNoEnum.YES)
                .update();
    }
}
